#include "sort.h"

// 宏，用于存储函数名称
#define __TEST__NAME__                                                       \
    "bubble_sort_1", "bubble_sort_2", "select_sort_1", "select_sort_2",      \
        "insert_sort", "shell_sort", "heap_sort", "merge_sort",              \
        "merge_sort_nor", "count_sort", "count_sort_stable", "quick_sort_1", \
        "quick_sort_2", "quick_sort_nor"
// 宏，用于存储函数指针
#define __TEST__FUNC__                                                       \
    bubble_sort_1, bubble_sort_2, select_sort_1, select_sort_2, insert_sort, \
        shell_sort, heap_sort, merge_sort, merge_sort_nor, count_sort,       \
        count_sort_stable, quick_sort_1, quick_sort_2, quick_sort_nor
// 宏，用于存储测试数组
#define __TEST__ARR__ 1, 9, 7, 5, 5, 0, 4, 8, 2, 6, 3, 2, 1

void test_all(int *arr, int n, void (*func)(int *, int)) {
    func(arr, n);
    FOR(i, n, "%d", arr[i]);
}

int main() {
    const char *name[] = {__TEST__NAME__};

    void (*test_alls[])() = {__TEST__FUNC__};

    int all = sizeof(test_alls) / sizeof(*test_alls);

    int arr[] = {__TEST__ARR__};
    int n = sizeof(arr) / sizeof(*arr);
    printf("-------------------before sort-------------------\n");
    FOR(i, n, "%d", arr[i]);
    for (int i = 0; i < all; i++) {
        // c语言特性：相同变量在内层重新定义会被覆盖，可以与外层变量同名
        int arr[] = {__TEST__ARR__};
        int n = sizeof(arr) / sizeof(*arr);
        printf("==============%s_test===============\n", name[i]);
        test_all(arr, n, test_alls[i]);
    }
    return 0;
}